// 依赖倒转原则
package main

import "fmt"

// ----->抽象层<-----

type Car interface {
	Run()
}

type Driver interface {
	Drive(car Car)
}

// ----->实现层<-----

type BenZ struct{}

func (b *BenZ) Run() {
	fmt.Println("BenZ is running...")
}

type BMW struct{}

func (b *BMW) Run() {
	fmt.Println("BMW is running...")
}

type Bob struct{}

func (b *Bob) Drive(car Car) {
	fmt.Println("Bob drive car")
	car.Run()
}

type Tom struct{}

func (t *Tom) Drive(car Car) {
	fmt.Println("Tom drive car")
	car.Run()
}

// ----->业务逻辑层<-----
func main() {
	var benz Car
	benz = &BenZ{}

	var bob Driver
	bob = new(Bob)

	bob.Drive(benz)

	// ------------------------------

	var bmw Car
	bmw = new(BMW)

	var tom Driver
	tom = new(Tom)

	tom.Drive(bmw)
}
